home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / FILL1.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  3KB  |  107 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 05-28-93 (07:58)             Number: 223
  4. From: BRENDA HOLLOWAY              Refer#: NONE
  5.   To: ROBERT CADENA                 Recvd: NO  
  6. Subj: Windows from TP to TC          Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. BH->character is an attribute byte. The low order byte of each
  9. BH->word is the character, the high byte of each word is the
  10. BH->attribute for the character.
  11.  
  12.  RC> Thank you... I'm kinda new to TC so how do you change/read bytes...
  13.  
  14. Like this! <g>
  15.  
  16. /* Fills a window on the screen with a line of text */
  17. /* Demo program for C_ECHO by Brenda Holloway. */
  18.  
  19. #include <conio.h>
  20. #include <stdlib.h>
  21.  
  22. /* The "glom" macro gloms together the character and attribute into
  23.    an unsigned short integer, like the screen memory uses.
  24.  */
  25.  
  26. #define glom( ch, attr )        ( (unsigned)(ch) | ((unsigned)(attr)<<8) )
  27.  
  28. /* WHITE_ON_RED uses constants from conio.h to form an attribute;
  29.    the bottom four bits are the foreground color, the next three the
  30.    background color, and the high bit, if on, blinks the character.
  31.  */
  32.  
  33. #define WHITE_ON_RED            ( WHITE | (RED<<4) )
  34.  
  35. /* Prototype for PutDemo. */
  36.  
  37. void PutDemo( int left, int top, int right, int bottom, char *s );
  38.  
  39. /* main. Clear the screen, put the block of text on the screen,
  40.    prompt the user, wait for a key, and hit the road.
  41.  */
  42.  
  43. void main()
  44. {
  45.         clrscr();
  46.         PutDemo( 10, 10, 40, 20, "I can C so very clearly " );
  47.         gotoxy(1,24);
  48.         cputs( "Hit nearly any key to continue..." );
  49.         getch();
  50. }
  51.  
  52. /* PutDemo. Takes a window on the screen defined by left, top, right,
  53.    and bottom, and fills it with the string in 's' in white-on-red
  54.    characters.
  55.  */
  56.  
  57. void PutDemo( int left, int top, int right, int bottom, char *s )
  58. {
  59.         /* numChars - the number of characters to fill. */
  60.  
  61.         int numChars = (right-left+1) * (bottom-top+1);
  62.  
  63.         /* buffer - our screen buffer. Note that it's made of short
  64.            integers AND NOT characters, since that's how screen memory
  65.            actually looks.
  66.          */
  67.  
  68.         short *buffer = calloc( numChars, sizeof(short) );
  69.  
  70.         /* If we got the buffer... */
  71.  
  72.         if( buffer != NULL )
  73.         {
  74.                 /* And there's anything to do... */
  75.  
  76.                 if( *s && numChars )
  77.                 {
  78.                         char *ps = s;
  79.                         short i = 0;
  80.  
  81.                         /* Fill the buffer with the string */
  82.  
  83.                         while( i<numChars )
  84.                         {
  85.                                 if( *ps == '\0' )
  86.                                         ps = s;
  87.                                 buffer[i++] = glom( *ps++, WHITE_ON_RED );
  88.                         }
  89.  
  90.                         /* Blast it to the screen... */
  91.  
  92.                         puttext( left, top, right, bottom, buffer );
  93.                 }
  94.  
  95.                 /* Free the buffer now. */
  96.  
  97.                 free( buffer );
  98.         }
  99. }
  100.  
  101.  
  102. --- Maximus 2.01wb
  103.  * Origin: Two Birds -- One Stone BBS (1:216/37)
  104. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  105. SEEN-BY: 153/752 154/40 77 157/110 159/100 125 575 950 203/23 209/209
  106. SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  107.